package edu.usm.roberge.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class Main extends Composite {

	private static MainUiBinder uiBinder = GWT.create(MainUiBinder.class);
	
	@UiField Button searchBtn;
	@UiField InputElement cityTxt;
	@UiField InputElement stateTxt;
	@UiField GolfCourseListView gcView;

	private GolfCourseAsyncProvider prov;
	private PricesAsyncProvider gprov;
	private WeatherAsyncProvider wap;

	interface MainUiBinder extends UiBinder<Widget, Main> {
	}

	public Main(PricesAsyncProvider gprov, GolfCourseAsyncProvider prov2, WeatherAsyncProvider wap) {
		initWidget(uiBinder.createAndBindUi(this));
		this.gprov = gprov;
		this.prov = prov2;
		this.wap = wap;
		prov.addDataDisplay(gcView.getGolfCourseList());
	}

	public Main(String firstName) {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiHandler("searchBtn")
	public void handleSearch(ClickEvent event) {
		gprov.getAirlinePrices(cityTxt.getValue());
		prov.getGolfCourses(cityTxt.getValue(), stateTxt.getValue());
		wap.getWeatherForecast(cityTxt.getValue(), stateTxt.getValue());
	}
}
